home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / prcgntn1.lha / Precognition / source / precognition_utils.c < prev    next >
C/C++ Source or Header  |  1992-12-23  |  2KB  |  129 lines

  1. #define PRECOGNITION_UTILS_BODY
  2.  
  3. #include "precognition_utils.h"
  4. #include "minmax.h"
  5. #include <proto/exec.h>
  6. #include <proto/intuition.h>
  7. #include <proto/graphics.h>
  8. #include "amigamem.h"
  9. #include <string.h>
  10.  
  11. TextAttr pcg_Topaz80 =
  12.    { "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT };
  13.  
  14.  
  15.  
  16.  
  17.  
  18. #define RES_MASK (HIRES+LACE)
  19. #define LO_RES             0
  20. #define LO_RES_INTERLACE   LACE
  21. #define HI_RES             HIRES
  22. #define HIRES_INTERLACE    HIRES+LACE
  23.  
  24. tPoint pcg_AspectRatio( USHORT ViewModes )
  25. {
  26.    tPoint ratio;
  27.    USHORT ScreenRes;
  28.  
  29.    ScreenRes = (ViewModes & (RES_MASK)); /* Ignore other bits. */
  30.    switch (ScreenRes)
  31.    {
  32.       case LO_RES:
  33.       case HIRES_INTERLACE:
  34.          ratio.x = 1;
  35.          ratio.y = 1;
  36.          break;
  37.  
  38.       case LO_RES_INTERLACE:
  39.          ratio.x = 1;
  40.          ratio.y = 2;
  41.          break;
  42.  
  43.       case HIRES:
  44.          ratio.x = 2;
  45.          ratio.y = 1;
  46.          break;
  47.     }
  48.    return ratio;
  49. }
  50.  
  51.  
  52.  
  53. void ChainGadgets( Gadget *start_of_chain, Gadget *gadget )
  54. {
  55.    Gadget *g;
  56.  
  57.    for (g=start_of_chain; g->NextGadget !=NULL; g=g->NextGadget);
  58.    g->NextGadget = gadget;
  59. }
  60.  
  61.  
  62.  
  63.  
  64. #define FONTHEIGHT 9
  65. #define FONTWIDTH  8
  66.  
  67.  
  68. void AlignText( PrecogText    *ptext,
  69.                 Point          size  )
  70. {
  71.    PIXELS width;
  72.    UBYTE  flags;
  73.    BYTE   Xpad, Ypad;
  74.  
  75.  
  76.    flags = ptext->alignment.Flags;
  77.    Xpad  = ptext->alignment.Xpad;
  78.    Ypad  = ptext->alignment.Ypad;
  79.  
  80.    if (ptext->IText)
  81.    {
  82.       width = strlen(ptext->IText)*FONTWIDTH;
  83.    }
  84.    else
  85.    {
  86.       width = 0;
  87.    }
  88.  
  89.    /*--------------- ptext->LeftEdge = ? -------------------*/
  90.    if (flags & tx_XCENTER)
  91.    {
  92.       ptext->LeftEdge = size.x/2 - width/2;
  93.    }
  94.    else if (flags & tx_RIGHT)
  95.    {
  96.       if (flags & tx_OUTSIDE)
  97.          ptext->LeftEdge = size.x + Xpad;
  98.       else
  99.          ptext->LeftEdge = size.x - Xpad - width;
  100.    }
  101.    else /* left */
  102.    {
  103.       if (flags & tx_OUTSIDE)
  104.          ptext->LeftEdge = -Xpad - width;
  105.       else
  106.          ptext->LeftEdge = Xpad;
  107.    }
  108.  
  109.    /*--------------- ptext->TopEdge = ? ---------*/
  110.    if (flags & tx_YCENTER)
  111.    {
  112.       ptext->TopEdge = size.y/2 - FONTHEIGHT/2;
  113.    }
  114.    else if (flags & tx_BOTTOM)
  115.    {
  116.       if (flags & tx_OUTSIDE)
  117.          ptext->TopEdge = size.y + Ypad;
  118.       else
  119.          ptext->TopEdge = size.y - Ypad - FONTHEIGHT;
  120.    }
  121.    else /* Top */
  122.    {
  123.       if (flags & tx_OUTSIDE)
  124.          ptext->TopEdge = -Ypad - FONTHEIGHT;
  125.       else
  126.          ptext->TopEdge = Ypad;
  127.    }
  128.  
  129. }